import { Injectable } from '@nestjs/common';
import { Redis } from 'ioredis';

@Injectable()
export class RedisCacheService {
  constructor(private readonly redis: Redis) {}

  // 获取redis
  async get(key) {
    const res = await this.redis.get(key);
    return JSON.parse(res);
  }

  // 设置redis
  async set(key, value) {
    return await this.redis.set(key, JSON.stringify(value));
  }

  // delete
  async delete(key) {
    return await this.redis.del(key);
  }
}
